package IC.AST.nodes;

import java.util.List;

import IC.lir.operands.Label;
import IC.AST.*;
import IC.lir.LIREntry;
import IC.asm.ASMEntry;

/**
 * a method declaration
 */
public class MethodDecl extends ASTNode {
	private String methodName;	// the method name
	private TypeDecl returnType;	// the return type
	private List<FormalDecl> formals;	// the formal arguments
	private Statement body;	// the method body
	private boolean isStatic;	// whether the method is static
	private List<LIREntry> lirCode; // the generated LIR code
	private List<ASMEntry> asmCode; // the generated LIR code
	private String methodLabel; // the label to where the method starts
	private int numLocals;
	
	/**
	 * @return the numLocals
	 */
	public int getNumLocals() {
		return numLocals;
	}

	/**
	 * @param numLocals the numLocals to set
	 */
	public void setNumLocals(int numLocals) {
		this.numLocals = numLocals;
	}

	/**
	 * @param methodName the method name
	 * @param returnType the return type
	 * @param formals the formal arguments
	 * @param body the method body
	 * @param isStatic whether the method is static
	 * @param fileName TODO
	 * @param line the node line number
	 * @param column the node column number
	 */
	public MethodDecl(String methodName, TypeDecl returnType, List<FormalDecl> formals, Statement body, boolean isStatic, String fileName, int line, int column) {
		super(fileName,line, column);
		this.methodName = methodName;
		this.returnType = returnType;
		this.formals = formals;
		this.body = body;
		this.isStatic = isStatic;
	}

	/**
	 * @return the method name
	 */
	public String getMethodName() {
		return this.methodName;
	}

	/**
	 * @return the return type
	 */
	public TypeDecl getReturnType() {
		return this.returnType;
	}

	/**
	 * @return the formal arguments
	 */
	public List<FormalDecl> getFormals() {
		return this.formals;
	}

	/**
	 * @return the method body
	 */
	public Statement getBody() {
		return this.body;
	}

	/**
	 * @return the lirCode
	 */
	public List<LIREntry> getLirCode() {
		return lirCode;
	}

	/**
	 * @param lirCode the lirCode to set
	 */
	public void setLirCode(List<LIREntry> lirCode) {
		this.lirCode = lirCode;
	}

	/**
	 * @return the asmCode
	 */
	public List<ASMEntry> getAsmCode() {
		return asmCode;
	}

	/**
	 * @param asmCode the asmCode to set
	 */
	public void setAsmCode(List<ASMEntry> asmCode) {
		this.asmCode = asmCode;
	}

	/**
	 * @return whether the method is static
	 */
	public boolean isStatic() {
		return this.isStatic;
	}

	public <D,U> U accept(PropogatingVisitor<D,U> v, D context) throws Exception {
		return v.visit(this,context);
	}

	/**
	 * @return the methodLabel
	 */
	public String getLabel() {
		return methodLabel;
	}

	/**
	 * @param methodLabel the methodLabel to set
	 */
	public void setLabel(String methodLabel) {
		this.methodLabel = methodLabel;
	}
}
